new Vue({
  el: '#app',
  data() {
    return {
      form: {
        level:'',
        order:'',
        Model_Name:'',
        page: 1,			//页数
        limit: 10,			//每页数据条数
        token:$.cookie('token')
      },
      total: 0,
      tableData: [],		//表格数据
    }
  },
  mounted() {
    this.getList(this.form)
  },
  computed:{
    Level(){
      return function (level) {
        if (level=='1') {
          return '一级菜单'
        }else if (level=='2') {
          return '二级菜单'
        }else if (level=='3') {
          return '三级菜单'
        }else{
          return ''
        }
      }
    }
  },
  methods: {
    onSerach() {				//查询方法
      this.form.page = 1;
      this.getList(this.form)
    },
    addContract() {
      window.location.href = './Add.html'
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getMenuAllAction`,
        data,
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          if(Result.Status=='success'){
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
          }
        },
        dataType: "json"
      });
    },
    editMember(Model_Number) {
      sessionStorage.setItem("Model_Number", Model_Number)
      window.location.href = './Edit.html?Model_Number=' + Model_Number
    },
    deletMember(Model_Number) {
      this.$confirm('警告！此操作将删除此菜单栏目, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.delete(Model_Number);
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消删除'
        });
      });
    },
    delete(Model_Number) {
      const _this = this
      $.ajax({
        url: DomainName + '/GoodsInquiryKeyOriginal',
        type: 'POST',
        data:{
          Data:'system_model_list',
          Primary_Key:Model_Number,
          Primary_Key_Name:'Model_Number'
        },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            $.ajax({
              url: `${DomainName}/getEditAction?token=${$.cookie("token")}`,
              type: 'POST',
              data:{ Data: JSON.stringify({ Modify: { system_model_list: [res[0]] } }) },
              success:function (res) {
                if (res.Status == 'success') {
                  _this.getList(_this.form);
                  _this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})